﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UnitTestDocumentStoreBuilder.cs" company="SaltFx">
//   Copyright (c) SaltFx - All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace SaltFx.Data.RavenDB.Tests
{
	using Raven.Client;
	using Raven.Client.Embedded;

	/// <summary>
	/// The unit test document store builder.
	/// </summary>
	public class UnitTestDocumentStoreBuilder : IDocumentStoreBuilder
	{
		#region Constants and Fields

		/// <summary>
		/// The document store.
		/// </summary>
		private IDocumentStore documentStore;

		#endregion

		#region Public Methods and Operators

		/// <summary>
		/// Builds a configured session factory.
		/// </summary>
		/// <returns>
		/// The configured session factory.
		/// </returns>
		public IDocumentStore Build()
		{
			if (this.documentStore != null)
			{
				return this.documentStore;
			}

			this.documentStore = new EmbeddableDocumentStore
			{
				RunInMemory = true
			};

			this.documentStore.Initialize();

			return this.documentStore;
		}

		#endregion
	}
}